package com.example.hxpc.guidancemanagement.activity;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.Paint;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.Spanned;
import android.text.method.LinkMovementMethod;
import android.text.style.ClickableSpan;
import android.text.style.ForegroundColorSpan;
import android.view.View;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.hxpc.guidancemanagement.R;
import com.example.hxpc.guidancemanagement.tools.LogoutT;

/**
 * Created by tao on 2018/3/16.
 */

public class ProjectDetailActivity extends Activity implements View.OnClickListener{
    private ImageView img_add , img_back;
    private TextView te_title , te_sure;
    private TextView te_pro_name,te_join_num,te_pro_state,te_pro_teacher,te_pro_path;
    private SpannableString spannableString;
    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.activity_project_detail);
        initView();
        getData();
    }
    public void initView(){
        img_add = (ImageView) findViewById(R.id.add_mark);
        img_add.setVisibility(View.GONE);
        img_back = (ImageView) findViewById(R.id.back);
        img_back.setOnClickListener(this);
        te_title = (TextView) findViewById(R.id.te_title);
        te_title.setText("项目详情");
        te_sure = (TextView) findViewById(R.id.sure);
        te_sure.setVisibility(View.GONE);
//        te_sure.setOnClickListener(this);
        te_pro_name = (TextView) findViewById(R.id.project_name);
        te_join_num = (TextView) findViewById(R.id.join_num);
        te_pro_state = (TextView) findViewById(R.id.project_state);
        te_pro_teacher = (TextView) findViewById(R.id.pro_teacher);
        te_pro_path= (TextView) findViewById(R.id.pro_path);
    }

    public void getData(){
        te_pro_name.setText(getIntent().getStringExtra("projectName"));
        te_join_num.setText(getIntent().getStringExtra("projectJoinNum"));
        te_pro_state.setText(getIntent().getStringExtra("projectState"));
        te_pro_teacher.setText(getIntent().getStringExtra("projectTeacher"));
        spannableString = new SpannableString(getIntent().getStringExtra("projectPath"));
        spannableString.setSpan(new ForegroundColorSpan(Color.BLUE),0,spannableString.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        ClickableSpan what = new ClickableSpan() {
            @Override
            public void onClick(View widget) {
                Intent intent = new Intent(ProjectDetailActivity.this, GoodProjectDetailActivity.class);
                intent.putExtra("resourcePath",getIntent().getStringExtra("projectPath"));
                startActivity(intent);
            }
        };
        spannableString.setSpan(what,0,spannableString.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        te_pro_path.setText(spannableString);
        te_pro_path.getPaint().setFlags(Paint. UNDERLINE_TEXT_FLAG );
        te_pro_path.setMovementMethod(LinkMovementMethod.getInstance());
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.back:
                finish();
                break;
        }
    }
}
